package com.sky.controller.admin;

import com.sky.dto.IdDto;
import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderListService;
import com.sky.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminOrderController")
@Slf4j
@Api(tags = "订单统计")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrderListService orderListService;
    @Autowired
    private OrderService orderService;

    @GetMapping("/conditionSearch")
    @ApiOperation("订单列表")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = orderListService.pageQuery(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result<String> confirm(@RequestBody IdDto idDto) {
        Integer orderId = idDto.getId();
        orderService.updateOrderStatus(orderId, 5);
        return Result.success("接单成功");
    }

    @GetMapping("/details/{id}")
    @ApiOperation("订单详情")
    public Result<Orders> getDetail(@PathVariable Integer id) {
//        OrdersDTO ordersDTO = new OrdersDTO();
        Orders orders = orderService.getOrdersById(id);
//        BeanUtils.copyProperties(orders, ordersDTO);
        List<OrderDetail> orderDetail = orderListService.getOrersById(id);
//        ordersDTO.setOrderDetails(orderDetail);
        return Result.success(orders);
    }
}
